unit uniDlgRelRepresentante;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DBCtrls, StdCtrls, Buttons, ExtCtrls;

type
  TfrmDlgRelRepresentante = class(TForm)
    Panel2: TPanel;
    btnFechar: TSpeedButton;
    btnImprimir: TSpeedButton;
    GroupBox2: TGroupBox;
    Label2: TLabel;
    dblRepresentante: TDBLookupComboBox;
    procedure btnImprimirClick(Sender: TObject);
    procedure btnFecharClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmDlgRelRepresentante: TfrmDlgRelRepresentante;

implementation

uses uniRelRepresentante;

{$R *.dfm}

procedure TfrmDlgRelRepresentante.btnImprimirClick(Sender: TObject);
var sSQL,
    sWhere:string;
begin
  sWhere := '';
  if dblRepresentante.Text <> '' then
    sWhere := sWhere + ' WHERE CD_REPRESENTANTE = '+IntToStr(dblRepresentante.KeyValue);

  sSQL := ' SELECT * FROM TB_REPRESENTANTE '+
          sWhere +
          ' ORDER BY NOME ';
   try
    Application.CreateForm(TfrmRelRepresentante, frmRelRepresentante);
    frmRelRepresentante.QR_Rel.close;
    frmRelRepresentante.QR_Rel.SQL.Text := sSQL;
    frmRelRepresentante.QR_Rel.Open;
    frmRelRepresentante.qrpRel.Preview;
   finally
     frmRelRepresentante.Free;
   end;
end;

procedure TfrmDlgRelRepresentante.btnFecharClick(Sender: TObject);
begin
Close;
end;

end.
